package org.xg.study.pd.test;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xg.study.pd.AuthLink;
import org.xg.study.pd.AuthService;
import org.xg.study.pd.impl.Level1AuthLink;
import org.xg.study.pd.impl.Level2AuthLink;
import org.xg.study.pd.impl.Level3AuthLink;

import java.text.ParseException;
import java.util.Date;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName ApiTest13_02
 * @date 2021/9/16 10:23
 **/
public class ApiTest13_02 {
    private Logger logger = LoggerFactory.getLogger(ApiTest13_02.class);

    @Test
    public void test_authLink() throws ParseException {
        AuthLink authLink = new Level3AuthLink("10003","王工")
                .appendNext(new Level2AuthLink("1003","王经理"))
                .appendNext(new Level1AuthLink("103","王总"));

        logger.info("测试结果：{}", JSONObject.toJSONString(authLink.doAuth("xg","1000000231456",new Date())));
        logger.info("====================分割线=======================");

        //模拟三级负责人审批
        AuthService.auth("10003","1000000231456");
        logger.info("测试结果：{}","模拟三级负责人审批，王工");
        logger.info("测试结果：{}",JSONObject.toJSONString(authLink.doAuth("xg","1000000231456",new Date())));
        logger.info("====================分割线=======================");

        //模拟二级负责人审批
        AuthService.auth("1003","1000000231456");
        logger.info("测试结果：{}","模拟二级负责人审批，王经理");
        logger.info("测试结果：{}",JSONObject.toJSONString(authLink.doAuth("xg","1000000231456",new Date())));
        logger.info("====================分割线=======================");

        //模拟一级负责人审批
        AuthService.auth("103","1000000231456");
        logger.info("测试结果：{}","模拟一级负责人审批，王总");
        logger.info("测试结果：{}",JSONObject.toJSONString(authLink.doAuth("xg","1000000231456",new Date())));
    }
}
